using System;
using System.Windows.Automation;
using ProdControls.Bridges;
using ProdControls.Interfaces;
using ProdLogging;

namespace ProdControls
{
    /// <summary>
    ///   Methods to work with Tab controls using the UI Automation framework
    ///   A tab control is analogous to the dividers in a notebook or the labels in a file cabinet. By using a tab control, an application can define multiple pages for the same area of a window or dialog box
    /// </summary>
    public sealed class ProdTab : BaseProdControl, ISelectionItem, IList
    {
        #region Constructors

        /// <summary>
        ///   Initializes a new instance of the ProdTab class.
        /// </summary>
        /// <param name="prodWindow"> The ProdWindow that contains this control. </param>
        /// <param name="automationId"> The UI Automation element </param>
        /// <remarks>
        ///   Will attempt to match AutomationId, then ReadOnly
        /// </remarks>
        public ProdTab(ProdWindow prodWindow, string automationId)
            : base(prodWindow, automationId)
        {
        }

        /// <summary>
        ///   Initializes a new instance of the ProdTab class.
        /// </summary>
        /// <param name="prodWindow"> The ProdWindow that contains this control. </param>
        /// <param name="treePosition"> The index of this control in the parent windows UI control tree. </param>
        public ProdTab(ProdWindow prodWindow, int treePosition)
            : base(prodWindow, treePosition)
        {
        }

        /// <summary>
        ///   Initializes a new instance of the ProdTab class.
        /// </summary>
        /// <param name="controlHandle"> Window handle of the control </param>
        public ProdTab(IntPtr controlHandle)
            : base(controlHandle)
        {
        }

        #endregion Constructors

        #region ISelectionItem Members

        /// <summary>
        ///   Gets a value that indicates whether an item is selected.
        /// </summary>
        /// <param name="text"> </param>
        /// <returns> </returns>
        /// <value> <c>true</c> if selected; otherwise, <c>false</c> . </value>
        [ProdLogging(LoggingLevels.Prod, VerbositySupport = LoggingVerbosity.Minimum)]
        public bool IsSelected(string text)
        {
            return this.IsSelectedHook(this, text);
        }

        /// <summary>
        ///   Determines whether the specified index is selected.
        /// </summary>
        /// <param name="index"> The index. </param>
        /// <returns> <c>true</c> if the specified index is selected; otherwise, <c>false</c> . </returns>
        [ProdLogging(LoggingLevels.Prod, VerbositySupport = LoggingVerbosity.Minimum)]
        public bool IsSelected(int index)
        {
            return this.IsSelectedHook(this, index);
        }

        /// <summary>
        ///   Adds the current element to the collection of selected items.
        /// </summary>
        /// <param name="text"> </param>
        [ProdLogging(LoggingLevels.Prod, VerbositySupport = LoggingVerbosity.Minimum)]
        public void AddToSelection(string text)
        {
            this.AddToSelectionHook(this, text);
        }

        /// <summary>
        ///   Adds the current element to the collection of selected items.
        /// </summary>
        /// <param name="index"> The index of the item. </param>
        [ProdLogging(LoggingLevels.Prod, VerbositySupport = LoggingVerbosity.Minimum)]
        public void AddToSelection(int index)
        {
            this.AddToSelectionHook(this, index);
        }

        /// <summary>
        ///   Removes the current element from the collection of selected items.
        /// </summary>
        /// <param name="text"> </param>
        [ProdLogging(LoggingLevels.Prod, VerbositySupport = LoggingVerbosity.Minimum)]
        public void RemoveFromSelection(string text)
        {
            this.RemoveFromSelectionHook(this, text);
        }

        /// <summary>
        ///   Removes the current element from the collection of selected items.
        /// </summary>
        /// <param name="index"> The index of the item. </param>
        [ProdLogging(LoggingLevels.Prod, VerbositySupport = LoggingVerbosity.Minimum)]
        public void RemoveFromSelection(int index)
        {
            this.RemoveFromSelectionHook(this, index);
        }

        /// <summary>
        ///   Deselects any selected items and then selects the current element
        /// </summary>
        /// <param name="text"> The text of the item to select. </param>
        [ProdLogging(LoggingLevels.Prod, VerbositySupport = LoggingVerbosity.Minimum)]
        public void Select(string text)
        {
            this.SelectHook(this, text);
        }

        /// <summary>
        ///   Deselects any selected items and then selects the current element
        /// </summary>
        /// <param name="index"> The index of the item to select. </param>
        [ProdLogging(LoggingLevels.Prod, VerbositySupport = LoggingVerbosity.Minimum)]
        public void Select(int index)
        {
            this.SelectHook(this, index);
        }

        #endregion

        public AutomationElementCollection ListItems => this.ListItemsHook(this);

        /// <summary>
        ///   Gets the selected items.
        /// </summary>
        /// <returns> </returns>
        [ProdLogging(LoggingLevels.Prod, VerbositySupport = LoggingVerbosity.Maximum)]
        public AutomationElement[] SelectedItems => this.SelectedItemsHook(this);

        public int ItemCount => this.ItemCountHook(this);

        public int SelectedItemCount => this.SelectedItemCountHook(this);
    }
}